<template>
    <div class="box">
      <h2>Son1 子组件</h2>
      从vuex中获取的值: <label>{{ count }}</label>
      <br>
      <button @click="handleAdd(1)">值 + 1</button>
      <button @click="handleAdd(5)">值 + 5</button>
      <button @click="handleAdd(10)">值 + 10</button>
      <button @click="changeTitle">改标题</button>
      <button @click="handleChange">一秒后修改成666</button>

      <hr>
      <!-- 计算属性 getters -->
      <div>{{ $store.state.list }}</div>
      <div>{{ $store.getters.filterList }}</div>

      <hr>
      <!-- 测试访问模块中的state -原生-  -->
      <div>{{ $store.state.user.userInfo.name }}</div>
        <button @click="updataUser">更新个人信息</button>
      <div>{{ $store.state.setting.theme }} </div>
        <button @click="updataTheme">更新主题色</button>

        <!-- 测试访问模块中的getters  -原生- -->
        <div>{{ $store.getters['user/UpperCaseName'] }}</div>
    </div>
  </template>

<script>
export default {
  name: 'Son1Com',
  methods: {
    updataUser () {
      // $state.commit('模块名/mutation名'，额外传参)
      this.$store.commit('user/setUser', {
        name: 'xiaom',
        age: 25
      })
    },
    updataTheme () {
      // $state.commit('模块名/mutation名'，额外传参)
      this.$store.commit('setting/setTheme', 'pink')
    },
    handleAdd (n) {
      // 应该通过mutation 核心概念进行数据修改
      this.$store.commit('addCount', n)
    },
    changeTitle () {
      this.$store.commit('changeTitle', '黑马程序员')
    },
    handleChange () {
      // 调用 action
      // this.$store.dispatch('action名字', 额外参数)
      this.$store.dispatch('changeCountAction', 666)
    }

  }
}
</script>

  <style lang="css" scoped>
  .box{
    border: 3px solid #ccc;
    width: 400px;
    padding: 10px;
    margin: 20px;
  }
  h2 {
    margin-top: 10px;
  }
  </style>
